import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

/* Layout */
import Layout from "@/layout";

/* Router Modules */
// import componentsRouter from './modules/components'
// import chartsRouter from './modules/charts'
// import tableRouter from './modules/table'
// import nestedRouter from './modules/nested'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    noCache: true                if set true, the page will no be cached(default is false)
    affix: true                  if set true, the tag will affix in the tags-view
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  // {
  //   path: '/redirect',
  //   component: Layout,
  //   hidden: true,
  //   children: [
  //     {
  //       path: '/redirect/:path(.*)',
  //       component: () => import('@/views/redirect/index')
  //     }
  //   ]
  // },
  {
    path: "/login",
    component: () => import("@/views/login/index"),
    hidden: true,
  },
  {
    path: "/auth-redirect",
    component: () => import("@/views/login/auth-redirect"),
    hidden: true,
  },
  // {
  //   path: '/404',
  //   component: () => import('@/views/error-page/404'),
  //   hidden: true
  // },
  // {
  //   path: '/401',
  //   component: () => import('@/views/error-page/401'),
  //   hidden: true
  // },
  {
    path: "/",
    component: Layout,
    redirect: "/dashboard",

    children: [
      {
        path: "dashboard",
        component: () => import("@/views/dashboard/appHome"),
        name: "Dashboard",
        meta: { title: "首页", icon: "dashboard", affix: true },
      },
    ],
  },
  // ,

  // {
  //   path: '/profile',
  //   component: Layout,
  //   redirect: '/profile/index',
  //   hidden: true,
  //   children: [
  //     {
  //       path: 'index',
  //       component: () => import('@/views/profile/index'),
  //       name: 'Profile',
  //       meta: { title: 'Profile', icon: 'user', noCache: true }
  //     }
  //   ]
  // }
];

export const adminRoutes = [
  {
    path: "/sysUserManagment",
    name: "sysUserManagment",
    component: Layout,
    meta: {
      title: "系统用户管理", // 菜单标题
      icon: "el-icon-star-off", // 图标
      hasSubMenu: true, // 是否包含子菜单
    },
    children: [
      {
        path: "/sysUserList",
        component: (resolve) =>
          require(["@/views/system/sysUserList"], resolve),
        name: "sysUserList",
        meta: { title: "系统用户管理", affix: false },
      },
    ],
  },
  {
    path: "/userManagment",
    name: "userManagment",
    component: Layout,
    meta: {
      title: "用户管理", // 菜单标题
      icon: "el-icon-star-off", // 图标
      hasSubMenu: true, // 是否包含子菜单
    },
    children: [
      {
        path: "/userList",
        component: (resolve) => require(["@/views/system/userList"], resolve),
        name: "userList",
        meta: { title: "用户管理", affix: false },
      },
    ],
  },
  {
    path: "/goods",
    name: "goods",
    component: Layout,
    meta: {
      title: "商家管理", // 菜单标题
      icon: "el-icon-star-off", // 图标
      hasSubMenu: true, // 是否包含子菜单
    },
    children: [
      {
        path: "/goods",
        component: (resolve) => require(["@/views/system/goodsList"], resolve),
        name: "goods",
        meta: { title: "商家管理", affix: false },
      },
    ],
  },
  {
    path: "/message",
    name: "messageMarage",
    component: Layout,
    meta: {
      title: "对话管理", // 菜单标题
      icon: "el-icon-star-off", // 图标
      hasSubMenu: true, // 是否包含子菜单
    },
    children: [
      {
        path: "/message",
        component: (resolve) => require(["@/views/system/message"], resolve),
        name: "message",
        meta: { title: "对话管理", affix: false },
      },
    ],
  },
  {
    path: "/houseManagment",
    name: "houseManagment",
    component: Layout,
    meta: {
      title: "房屋管理", // 菜单标题
      icon: "el-icon-star-off", // 图标
      hasSubMenu: true, // 是否包含子菜单
    },
    children: [
      {
        path: "/houseList",
        component: (resolve) => require(["@/views/system/houseList"], resolve),
        name: "houseList",
        meta: { title: "房屋管理", affix: false },
      },
    ],
  },
  {
    path: "/reserve",
    name: "reserve",
    component: Layout,
    meta: {
      title: "预定管理", // 菜单标题
      icon: "el-icon-message", // 图标
      hasSubMenu: true, // 是否包含子菜单
    },
    children: [
      {
        path: "/reserve",
        component: (resolve) => require(["@/views/system/reserve"], resolve),
        name: "reserve",
        meta: { title: "预定管理", affix: false },
      },
    ],
  },
  {
    path: "/order",
    name: "order",
    component: Layout,
    meta: {
      title: "预定订单管理", // 菜单标题
      icon: "el-icon-info", // 图标
      hasSubMenu: true, // 是否包含子菜单
    },
    children: [
      {
        path: "/order",
        component: (resolve) => require(["@/views/system/order"], resolve),
        name: "reserve",
        meta: { title: "预定订单管理", affix: false },
      },
    ],
  },
  {
    path: "/traderOrder",
    name: "traderOrder",
    component: Layout,
    meta: {
      title: "订单佣金管理", // 菜单标题
      icon: "el-icon-user", // 图标
      hasSubMenu: true, // 是否包含子菜单
    },
    children: [
      {
        path: "/traderOrder",
        component: (resolve) => require(["@/views/system/traderOrder"], resolve),
        name: "reserve",
        meta: { title: "订单佣金管理", affix: false },
      },
    ],
  },
  {
    path: "/bonus",
    name: "bonus",
    component: Layout,
    meta: {
      title: "订单佣金管理", // 菜单标题
      icon: "el-icon-message", // 图标
      hasSubMenu: true, // 是否包含子菜单
    },
    children: [
      {
        path: "/bonus",
        component: (resolve) => require(["@/views/system/bonus"], resolve),
        name: "reserve",
        meta: { title: "bonus", affix: false },
      },
    ],
  },
  {
    path: "/orderManagment",
    name: "orderManagment",
    component: Layout,
    meta: {
      title: "看房纪录管理", // 菜单标题
      icon: "el-icon-star-off", // 图标
      hasSubMenu: true, // 是否包含子菜单
    },
    children: [
      {
        path: "/orderList",
        component: (resolve) => require(["@/views/system/orderList"], resolve),
        name: "orderList",
        meta: { title: "看房纪录管理", affix: false },
      },
    ],
  },
  {
    path: "/dictManagment",
    name: "dictManagment",
    component: Layout,
    meta: {
      title: "字典数据管理", // 菜单标题
      icon: "el-icon-star-off", // 图标
      hasSubMenu: true, // 是否包含子菜单
    },
    children: [
      {
        path: "/dictList",
        component: (resolve) => require(["@/views/system/dictList"], resolve),
        name: "dictList",
        meta: { title: "字典数据管理", affix: false },
      },
    ],
  },
  {
    path: "/locationItemManagment",
    name: "locationItemManagment",
    component: Layout,
    meta: {
      title: "地图数据管理", // 菜单标题
      icon: "el-icon-star-off", // 图标
      hasSubMenu: true, // 是否包含子菜单
    },
    children: [
      {
        path: "/locationItemList",
        component: (resolve) =>
          require(["@/views/system/locationItemList"], resolve),
        name: "locationItemList",
        meta: { title: "地图数据管理", affix: false },
      },
    ],
  },
];

const createRouter = () =>
  new Router({
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes,
  });

const router = createRouter();

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
